using UnityEngine;

public abstract class FallingObjectBehaviour : MonoBehaviour
{
	protected BaseGameManager _gameManager;

	protected FallingObject _fallingObject;

	protected int _holeId = -1;

	protected Transform _cachedTransform;

	protected bool _isDestroyed;

	public FallingObject FallingObject => _fallingObject;

	public bool IsDestroyed => _isDestroyed;

	protected virtual void Awake()
	{
		_cachedTransform = base.transform;
		_fallingObject = GetComponent<FallingObject>();
	}

	private void OnTriggerEnter(Collider other)
	{
		if (other.CompareTag("PipeBottom"))
		{
			Hole componentInParent = other.GetComponentInParent<Hole>();
			_holeId = componentInParent.PlayerId;
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (other.CompareTag("PipeDestroy"))
		{
			DisableObject();
		}
	}

	public void SetGameManager(BaseGameManager manager)
	{
		_gameManager = manager;
	}

	public void SetFallingObject(FallingObject fo)
	{
		_fallingObject = fo;
	}

	public abstract void ForceDisableObject();

	public abstract void DisableObject();

	public bool IsValidTarget(int level)
	{
		if (_isDestroyed)
		{
			return false;
		}
		if (_fallingObject.BotSizeRequired <= 4)
		{
			Vector3 position = _cachedTransform.position;
			if (position.y > 2.5f)
			{
				return false;
			}
		}
		return _fallingObject.BotSizeRequired <= level;
	}

	public Transform GetTargetTransform()
	{
		return _cachedTransform;
	}
}
